package cn.dmp.tags

import org.apache.commons.lang.StringUtils
import org.apache.spark.broadcast.Broadcast
import org.apache.spark.sql.Row

object Tags4App extends Tags{
    /**
      * 行数据 -》 标签数据
      *
      * @param args
      * @return
      */
    override def makeTags(args: Any*): Map[String, Int] = {

        var tags = Map[String, Int]()

        // 解析参数
        val row = args(0).asInstanceOf[Row]
        val appdictBroadcast = args(1).asInstanceOf[Broadcast[Map[String, String]]]

        // 打app的标签
        val appId = row.getAs[String]("appid")
        val appName = row.getAs[String]("appname")
        if (StringUtils.isEmpty(appName)) {
            if (StringUtils.isNotEmpty(appId)) {
                val appNameNew = appdictBroadcast.value.getOrElse(appId, appId)
                tags += "APP"+appNameNew -> 1
            }
        } else { // appName不是空的
            tags += "APP"+appName -> 1
        }
        tags
    }

}
